home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / pcpilot.arc / PCPILOT.C < prev    next >
Text File  |  1990-01-14  |  5KB  |  246 lines

  1. /*
  2.     PCPILOT.C - This is the main() module for PCPILOT.EXE.  It should be
  3.                 compiled in the small or tiny memory model.  See the
  4.                 README.1ST file for important info on compiling and
  5.                 running this program.
  6. */
  7.  
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <dos.h>
  11. #include <scr.h>
  12. #include <kbd.h>
  13.  
  14. int BorderClr = 0x09;
  15. int TitleClr = 0x0c;
  16. int TextClr = 0x0f;
  17. int FooterClr = 0x0b;
  18. int HighlightClr = 0x4f;
  19.  
  20. int Code = 0;                /* For Ascii()       */
  21. int BoxIdx = 0;             /* For BoxCodes()    */
  22. int ClrIdx = 0x00;            /* For ColorCodes()  */
  23. unsigned long NumIdx = 0L;    /* For BaseConvert() */
  24. int Row = 0, Col = 0;       /* For Ruler()       */
  25.  
  26. void PcPilot(void);
  27. void Initialize(void);
  28. static int videomode(void);
  29. void TitleScreen(void);
  30.  
  31. /*  #define DEBUG  */
  32. char signature[] = "PC-PILOT";
  33. extern unsigned _heaplen = 12288;
  34. extern unsigned _stklen = 1024;
  35. extern unsigned scancode[], keymask[];
  36. extern int unloading;                     /* To UnInstall TSR */
  37. void main(int argc, char *argv[])
  38. {
  39.     while (--argc > 0)    {
  40.         ++argv;
  41.         if (**argv != '-')
  42.             break;
  43.         if (tolower(argv[0][1]) == 'x')    {
  44.             Initialize();
  45.             PcPilot();
  46.             return;
  47.         }
  48.     }
  49.     Initialize();
  50.     *scancode= 76;                /* Alt(8) - '5'(76) on the keypad */
  51.     *keymask = 8;
  52.     tsr(PcPilot, TitleScreen);
  53. }
  54.  
  55. typedef struct {
  56.     char *str;
  57.     int y;
  58. } MENU;
  59.  
  60. MENU m[] = {
  61.     " Ascii Table    ",  8,
  62.     " Box Characters ",  9,
  63.     " Hex/Dec/Binary ", 10,
  64.     " Keyboard Codes ", 11,
  65.     " Ruler          ", 12,
  66.     " Color Codes    ", 13,
  67.     " Printer Setup  ", 14,
  68.     " Uninstall      ", 15,
  69.     " Exit           ", 16
  70. };
  71.  
  72. int Idx = 0;
  73. int K;
  74. int oldx, oldy;
  75.  
  76. static void DrawMenu(void);
  77. static void HighLight(int code);
  78. static void ExecuteMenuOptions(int index);
  79.  
  80. void PcPilot()
  81. {
  82.     ScrGetCur(&oldx, &oldy, 0);
  83.     HideCur();
  84.     ScrPush();
  85.     DrawMenu();
  86.  
  87.     for (;;)    {
  88.         HighLight(1);
  89.         switch (K = KbdGetC())    {
  90.             case UP:
  91.             case LEFT:
  92.                 HighLight(0);
  93.                 if (--Idx < 0) Idx = 8;
  94.                 break;
  95.             case DN:
  96.             case RIGHT:
  97.                 HighLight(0);
  98.                 if (++Idx > 8) Idx = 0;
  99.                 break;
  100.             case PGUP:
  101.             case HOME:
  102.                 HighLight(0);
  103.                 Idx = 0;
  104.                 break;
  105.             case PGDN:
  106.             case END:
  107.                 HighLight(0);
  108.                 Idx = 8;
  109.                 break;
  110.             case RET:
  111.                 if (Idx == 7 || Idx == 8)    {
  112.                     if (Idx == 7) unloading = 1;
  113.                     ScrPop(1);
  114.                     ScrSetCur(oldx, oldy, 0);
  115.                     return;
  116.                 }
  117.                 if (Idx == 4)    {
  118.                     ScrPop(1);
  119.                     Ruler();
  120.                     ScrPush();
  121.                     DrawMenu();
  122.                 }
  123.                 ExecuteMenuOptions(Idx);
  124.                 break;
  125.             case ESC:
  126.                 ScrPop(1);
  127.                 ScrSetCur(oldx, oldy, 0);
  128.                 return;
  129.             default:
  130.                 if ((K = K&0x00ff) != 0)    {
  131.                     if (!strchr("abhkrcpue", tolower(K))) break;
  132.                     HighLight(0);
  133.                     switch (tolower(K))    {
  134.                         case 'a': Idx = 0; break;
  135.                         case 'b': Idx = 1; break;
  136.                         case 'h': Idx = 2; break;
  137.                         case 'k': Idx = 3; break;
  138.                         case 'r': Idx = 4;
  139.                             ScrPop(1);
  140.                             Ruler();
  141.                             ScrPush();
  142.                             DrawMenu();
  143.                             break;
  144.                         case 'c': Idx = 5; break;
  145.                         case 'p': Idx = 6; break;
  146.                         case 'u': Idx = 7;
  147.                             unloading = 1;
  148.                         case 'e': Idx = 8;
  149.                                   ScrPop(1);
  150.                                   ScrSetCur(oldx, oldy, 0);
  151.                                   return;
  152.                         default : continue;
  153.                     }
  154.                     HighLight(1);
  155.                     ExecuteMenuOptions(Idx);
  156.                 }
  157.                 break;
  158.         }
  159.     }
  160. }
  161.  
  162. static void DrawMenu()
  163. {
  164.     register int i;
  165.  
  166.     ShadowBox(31,5,48,19, 2, BorderClr);
  167.     PutStr(32,6, TitleClr, "   PC - PILOT   ");
  168.     PutStr(31,7, BorderClr,"╞════════════════╡");
  169.     PutStr(31,17,BorderClr,"╞════════════════╡");
  170.     PutStr(32,18,FooterClr," %c %c <Esc> exits", 24,25);
  171.  
  172.     for (i=0; i<9; i++)    {
  173.         PutStr(32,8+i, TextClr, "%s", m[i].str);
  174.         PutStr(33,8+i, FooterClr, "%c", m[i].str[1]);
  175.     }
  176.     HighLight(1);
  177. }
  178.  
  179. static void HighLight(int code)
  180. {
  181.     switch (code)    {
  182.         case 0:
  183.             PutStr(32,m[Idx].y, TextClr, "%s", m[Idx].str);
  184.             PutStr(33,m[Idx].y, FooterClr, "%c", m[Idx].str[1]);
  185.             break;
  186.         case 1:
  187.             PutStr(32,m[Idx].y, ~TextClr & 0x7f, "%s", m[Idx].str);
  188.             PutStr(33,m[Idx].y, ~FooterClr & 0x7f, "%c", m[Idx].str[1]);
  189.             break;
  190.     }
  191. }
  192.  
  193. static void ExecuteMenuOptions(int index)
  194. {
  195.     switch (index)    {
  196.         case 0:  Ascii(); return;
  197.         case 1:  BoxCodes(); return;
  198.         case 2:  BaseConvert(); return;
  199.         case 3:  KeyCodes(); return;
  200.         case 4:  return;
  201.         case 5:  ColorCodes(); return;
  202.         case 6:  PrintCodes(); return;
  203.         case 7:  return;
  204.     }
  205. }
  206.  
  207. static void Initialize()
  208. {
  209.     int vmode;
  210.  
  211.     vmode = videomode();
  212.     if ((vmode != 2) && (vmode != 3) && (vmode != 7))    {
  213.         printf("Must be in 80 column text mode.\n");
  214.         exit(1);
  215.     }
  216.     InitScr();
  217.     if (VideoMode == MONO)    {
  218.         BorderClr     = 0x0f;
  219.         TitleClr      = 0x0f;
  220.         TextClr       = 0x07;
  221.         FooterClr     = 0x0f;
  222.         HighlightClr  = 0x70;
  223.     }
  224. }
  225.  
  226. static int videomode()
  227. {
  228.     union REGS r;
  229.  
  230.     r.h.ah = 15;
  231.     return int86(0x10, &r, &r) & 255;
  232. }
  233.  
  234. static void TitleScreen()
  235. {
  236.     Cls();
  237.     ShadowBox(18,8,59,16, 2, BorderClr);
  238.     PutStr(19,9, TextClr,    "               PC - PILOT               ");
  239.     PutStr(19,10, FooterClr, "           Programmer's Pop-Up          ");
  240.     PutStr(19,12, TextClr,   "     FREEware written by Tom Grubbe     ");
  241.     PutStr(19,13, TextClr,   " Released to the Public Domain 01-12-90 ");
  242.     PutStr(19,15, TextClr,   "          Alt-5 (keypad)                ");
  243.     PutStr(23,15, TitleClr,  "Press");
  244.     PutStr(44,15, TitleClr,  "To Activate");
  245.     ScrSetCur(0,18,0);
  246. }